package com.jingdianjichi.subject.infra.basic.utils;

import com.alibaba.druid.filter.config.ConfigTools;

import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;

/**
 * @Description: 数据库登录密码 加密
 * @return:
 * @Author:  sky
 * @date:  2024/11/6 22:20
 */
public class DruidEncryptUtil {
    private static String publicKey;
    private static String privateKey;

    static {
        try {
            String[] keyPair = ConfigTools.genKeyPair(512);
            privateKey = keyPair[0];
            //System.out.println(privateKey);
            publicKey = keyPair[1];
            //System.out.println(publicKey);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (NoSuchProviderException e) {
            e.printStackTrace();
        }
    }

    public static String encrypt(String text) throws Exception {
        return ConfigTools.encrypt(privateKey,text);
    }
    public static String decrypt(String text) throws Exception {
        return ConfigTools.decrypt(publicKey,text);
    }

//    public static void main(String[] args) throws Exception {
//        System.out.println(encrypt("Wing1Q2W#E"));
//        System.out.println(publicKey);
//    }
}
